#include "adapter.h"



Adapter::Adapter(QObject *parent) :
    QObject(parent)
{

}

void Adapter::setResData(  QList<QList<Item>>value)
{
    resData = value;
    tableFill();
}

void Adapter::tableOpen()
{

}

void Adapter::tableFill()
{
    QString sheet1Name = "num1";
    QAxWidget excel("Excel.Application");
    excel.setProperty("Visible", true);

    QAxObject * workbooks = excel.querySubObject("WorkBooks");
    QAxObject *workbook = workbooks->querySubObject("Open(const QString&)", "C:\\form.xls" );
    QAxObject * worksheets = workbook->querySubObject("WorkSheets");
    QAxObject *sheet1;
    int c ;
    int l = 1 ;

    foreach (QList<Item> _t, resData) {
        qDebug()<<_t.length();
        sheet1 = worksheets->querySubObject( "Item( int )",  l);
        QAxObject* cell = sheet1->querySubObject("Cells(int,int)", 1, 1);
        sheet1->dynamicCall("SetName(const QString&)", QVariant(sheet1Name));
        sheet1->dynamicCall("Select()");
        c = 0;

        for(int row = 4; row < _t.length()+4; row++)
        {
            cell = sheet1->querySubObject("Cells(int,int)", row, 2);
            cell->setProperty("Value", QVariant(_t[c].type));

            cell = sheet1->querySubObject("Cells(int,int)", row, 3);
            cell->setProperty("Value", QVariant(_t[c].design));

            cell = sheet1->querySubObject("Cells(int,int)", row, 4);
            cell->setProperty("Value", QVariant(_t[c].unit));

            cell = sheet1->querySubObject("Cells(int,int)", row, 5);
            cell->setProperty("Value", QVariant(_t[c].desc));

            cell = sheet1->querySubObject("Cells(int,int)", row, 7);
            cell->setProperty("Value", QVariant(_t[c].data[0]));

            cell = sheet1->querySubObject("Cells(int,int)", row, 8);
            cell->setProperty("Value", QVariant(_t[c].data[1]));

            cell = sheet1->querySubObject("Cells(int,int)", row, 9);
            cell->setProperty("Value", QVariant(_t[c].data[2]));

            cell = sheet1->querySubObject("Cells(int,int)", row, 10);
            cell->setProperty("Value", QVariant(_t[c].data[3]));

            cell = sheet1->querySubObject("Cells(int,int)", row, 11);
            cell->setProperty("Value", QVariant(_t[c].data[4]));

            cell = sheet1->querySubObject("Cells(int,int)", row, 12);
            cell->setProperty("Value", QVariant(_t[c].data[5]));

            cell = sheet1->querySubObject("Cells(int,int)", row, 13);
            cell->setProperty("Value", QVariant(_t[c].data[6]));
            c++;
        }
        l++;
        delete cell;
    }
    delete sheet1;
}

